package com.lx.algorithm.temp;

import com.pojo.ListNode;

import java.util.Stack;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-11-14 16:34:05
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-11-14     张李鑫                     1.0         1.0 Version
 */
public class NodeIsPail {



    public static boolean isPail (ListNode head) {
        // write code here

        Stack<Integer> listNodes = new Stack<>();
        ListNode cur=head;
        while (cur!=null){
            listNodes.add(cur.val);
            cur=cur.next;
        }
        while (!listNodes.isEmpty()){
            Integer pop = listNodes.pop();
            if (pop!=head.val){
                return false;
            }
            head=head.next;
        }
        return true;
    }

    public static void main(String[] args) {
        ListNode listNode = new ListNode(1);
        ListNode listNode1 = new ListNode(2);
        ListNode listNode2 = new ListNode(3);
        ListNode listNode3 = new ListNode(2);
        ListNode listNode4 = new ListNode(1);

        listNode.next = listNode1;
        listNode1.next = listNode2;
        listNode2.next = listNode3;
        listNode3.next = listNode4;



        ListNode listNode5=listNode;
        ListNode cur=listNode5.next;
        cur.next=listNode5;


        System.out.println(isPail(listNode));
        System.out.println(123);
    }
}